<!DOCTYPE html>
<html lang="en">
<head>
<title>动态组件</title>
<script src="./vue.js"></script>
</head>
 
<body>
	<div id="root">
		<component :is="type"></component>
		<!-- <childone v-if="type==='childone'"></childone>
		<childtwo v-if="type==='childtwo'"></childtwo> -->
		<button @click="handleClick">点击改变</button>
	</div>

	<script type="text/javascript">
	Vue.component('childone',{
	
		template:'<div v-once>childone</div>'
	})
	Vue.component('childtwo',{
	
		template:'<div v-once>childtwo</div>'
	})
	var vm=new Vue({
		el:"#root",
		data:{
			type:'childone'
		},
		methods:{
			handleClick:function(){
				this.type=this.type==='childone'?'childtwo':'childone';
			}
		}
	})
	</script>
</body>

</html>
